/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: agent-java
 * Description: Agent written in java language
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.agent.dao;

import ru.ffind.agent.db.DbDirectory;
import ru.ffind.agent.db.DbHost;
import ru.ffind.common.model.Directory;
import ru.ffind.common.model.HostType;

/**
 * Data access object.
 *
 * Interface for accessing objects in the database.
 *
 * @author Rage Steel
 */
public interface Dao {

	/**
	 * Find host by hostname and ip address
	 * Currently ip address is not used in search
	 *
	 * @param hostName
	 * @param ipAddress
     * @param hostType
	 * @return correspoing host or null if host not found
	 */
	DbHost findOrCreateHost(String hostName, int ipAddress, HostType hostType,
            String hostOwner);

	/**
	 * Lock host for crawling.
	 *
	 * @param host
	 * @return
	 */
	boolean lockHost(DbHost host);

    /**
     * Unlock host after crawling.
     *
     * @param host
     * @return
     */
	boolean unlockHost(DbHost host);

	/**
	 * Query for directory and it's content.
	 *
	 * @param dirId
	 * @param placeHolder object presenting directory without content
	 * @return
	 */
	DbDirectory queryDirectory(int dirId, DbDirectory placeHolder);

    /**
     * Set new root directory for host.
     * Also updates rootDirId value for host itself.
     *
     * @param host
     * @param rootDir
     */
    void updateHostRootDirId(DbHost host, DbDirectory rootDir);

    /**
     * Create new directory.
     * 
     * @param hostId
     * @param parentDir may be null
     * @param base
     * @return
     */
	DbDirectory createDir(Short hostId, DbDirectory parentDir, Directory base);

    /**
     * Update directory statistics.
     *
     * @param dir
     */
    void updateDirStats(DbDirectory dir);

    /**
     * Update directory information.
     * 
     * @param targetDir
     * @param base
     */
    void updateDir(DbDirectory targetDir, Directory base);

    /**
     * Non recursive delete all subdirectories and files of directory.
     *
     * @param dir
     */
  	void deleteDir(DbDirectory dir);

    /**
     * Create a batch for adding files.
     * 
     * @return
     */
    InsertFileBatch createInsertFileBatch();

    /**
     * Create a batch for updating files.
     *
     * @return
     */
    UpdateFileBatch createUpdateFileBatch();

    /**
     * Create a batch for deleting files.
     *
     * @return
     */
    DeleteFileBatch createDeleteFileBatch();

}
